﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVC4_Test.Models;

namespace MVC4_Test.Controllers
{
    public class HomeController : Controller
    {
        private StackOverflowContext db = new StackOverflowContext();
        //query systeem die uit de vragen model haalt een het featured
        public ActionResult Index( string tab = "interesting")
        {

            var result = db.Questions.Include("QuestionTag").Include("Answer").ToList();

            switch (tab)
            {
                case "featured":
                    result = db.Questions.Include("QuestionTag").ToList();
                    break;
                case "orderby":
                    result = db.Questions.Include("QuestionTag").OrderByDescending(p => p.Date).ToList();
                    break;
                case "hot":
                    result = db.Questions.Include("QuestionTag").OrderByDescending(p => p.View).ToList();
                    break;
                case "week":
                    result = db.Questions.Include("QuestionTag").OrderByDescending(p => p.Date.Day * 7).ToList();
                    break;
                case "month":
                    result = db.Questions.Include("QuestionTag").OrderByDescending(p => p.Date.Month).ToList();
                    break;
                default:
                    result = db.Questions.Include("QuestionTag").ToList();
                    break;

            }

            return View(result);
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }


        // roept de tags op en distinct ze
        // SideBar Tags 
        public ActionResult _RelatedTagSideBar()
        {
            return PartialView(db.Tags.ToList().Distinct());//db.QuestionTags.ToList().Distinct());
        }


        public ActionResult _RelatedTagSideBar2()
        {
            return View(db.Tags.ToList());//db.QuestionTags.ToList().Distinct());
        }

        // Test
        public ActionResult Test()
        {
            return View();
        }

        // Asynchronous calls
        public PartialViewResult Page_One()
        {
            return PartialView("_Page_One");
        }

        // Asynchronous calls
        public ActionResult Page_Two()
        {
            return PartialView("_Page_Two");
        }

    }
}
